package com.quyunshuo.module.home.activity.stat.chart

import java.text.SimpleDateFormat
import java.util.*

object DateUtils {
    private val dateFormat = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
    
    /**
     * 获取当前周的范围
     */
    fun getCurrentWeekRange(): Pair<String, String> {
        val calendar = Calendar.getInstance()
        calendar.firstDayOfWeek = Calendar.MONDAY
        calendar.time = Date()
        
        calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY)
        val startDate = dateFormat.format(calendar.time)
        
        calendar.add(Calendar.DATE, 6)
        val endDate = dateFormat.format(calendar.time)
        
        return startDate to endDate
    }
    
    /**
     * 获取指定周的日期范围
     * @param weekOffset 周偏移量（0=本周，-1=上周，1=下周）
     */
    fun getWeekRange(weekOffset: Int): Pair<String, String> {
        val calendar = Calendar.getInstance()
        calendar.firstDayOfWeek = Calendar.MONDAY
        calendar.time = Date()
        
        calendar.add(Calendar.WEEK_OF_YEAR, weekOffset)
        calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY)
        val startDate = dateFormat.format(calendar.time)
        
        calendar.add(Calendar.DATE, 6)
        val endDate = dateFormat.format(calendar.time)
        
        return startDate to endDate
    }
}